include(FindPackageHandleStandardArgs)

if(CCMD_LIBRARIES AND CCMD_INCLUDE_DIRS)
    # in cache already
    set(LibCCMD_FOUND TRUE)

    message(STATUS  "find include ${CCMD_INCLUDE_DIRS} lib ${CCMD_LIBRARIES} ===")
else()
    find_path(CCMD_INCLUDE_DIR
        NAMES
        ccmd/cmd.h
        PATHS
        /usr/include
        /usr/local/include
        /opt/local/include
        ${CMAKE_INCLUDE_PATH}
        ${CMAKE_INSTALL_PREFIX}/include
    )

    find_library(CCMD_LIBRARY
        NAMES
        ccmd
        libccmd
        PATHS
        /usr/lib
        /usr/lib64
        /usr/local/lib
        /usr/local/lib64
        /opt/local/lib
        ${CMAKE_LIBRARY_PATH}
        ${CMAKE_INSTALL_PREFIX}/lib
    )


    set(CCMD_INCLUDE_DIRS ${CCMD_INCLUDE_DIR})
    set(CCMD_LIBRARIES ${CCMD_LIBRARY})
    mark_as_advanced(CCMD_INCLUDE_DIRS CCMD_LIBRARIES)

    # handle the QUIETLY and REQUIRED arguments and set CCMD_FOUND to TRUE
    # if all listed variables are TRUE
    find_package_handle_standard_args(LibCCMD FOUND_VAR LibCCMD_FOUND
        REQUIRED_VARS CCMD_LIBRARY CCMD_INCLUDE_DIR)
endif()
